package stationGUI;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;
import java.net.UnknownHostException;

public class Client {
  private static final String HOST="1.paturi.usher.ucsdsys.net";
  
  public static void main(String[] args) throws IOException, Exception {

    //SuperStation s=new SuperStation();
    Socket socket = null;
    ObjectOutputStream out = null;
    //BufferedReader in = null;
    ObjectInputStream in = null;
    ClientNode clientNode;
    NodeBean inNode;
    NodeBean2 inNode2;

    try {
        socket = new Socket(HOST, 1099);
        System.out.println(socket);
        out = new ObjectOutputStream(socket.getOutputStream());
        in = new ObjectInputStream(socket.getInputStream());
    } catch (UnknownHostException e) {
        System.err.println("Don't know about host: "+HOST);
        System.exit(1);
    } catch (IOException e) {
        System.err.println("Couldn't get I/O for the connection to: "+HOST);
        System.exit(1);
    }

    inNode=(NodeBean)in.readObject();
    clientNode=new ClientNode(inNode,out);
    
    while ((inNode2 = (NodeBean2)in.readObject()) != null) {
      //System.out.println("I got a node! This is its color: "+inNode2.color);
      //System.out.println("This is my neighbors color: "+inNode2.neighbors.get(0));
      clientNode.update(inNode2);
    }

      out.close();
      in.close();
      socket.close();
  }
}
